package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.wx.service.GoodsGoodsService;
import com.bootdo.wx.service.GoodsTeamService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by HP on 2019/6/29.
 */
@Controller
@RequestMapping("/api/goodsTeam")
public class ApiGoodsTeamController {

    @Autowired
    private GoodsTeamService goodsTeamService;
    @Autowired
    private GoodsGoodsService goodsGoodsService;


    /*
    * 查询拼团商品列表
    * */
    @ResponseBody
    @RequestMapping("/getTeamGoods")
    public R getTeamGoods(@RequestBody Map<String,Object> paramMap) {
        try{
            if (!paramMap.containsKey("userId")) {
                return R.error("参数错误");
            }
            PageInfo<Map<String,Object>> list = goodsTeamService.getTeamGoodsList(paramMap);
            return R.ok().put("data", list);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }

    /**
     * 根据秒杀ID获取商品详情
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/goods/getDetail")
    public R getDetail(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("spikeId") || StringUtils.isBlank(params.get("spikeId").toString())
                ||!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())
                ){
            return R.error("缺少参数");
        }
        try {
            return goodsGoodsService.getSpikeDetail(params);
        }catch (Exception e){
            e.printStackTrace();
            return R.error("商品详情失败");
        }
    }



}
